﻿//using Maticsoft.DALFactory;
using Maticsoft.BLL;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using UI.Forms;

namespace UI
{
    public partial class Form1 : Form
    {
        Maticsoft.BLL.Users bll = new Maticsoft.BLL.Users();
        Maticsoft.BLL.Products products = new Maticsoft.BLL.Products();
        Users bllUsers = new Users();
        public Form1()
        {
            InitializeComponent();
            toolStripLabel1.Text = $"当前用户：【{ LoginInfo.CurrentUser.Account}】";
            toolStripLabel2.Text = $"系统时间：{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}";
            //Maticsoft.BLL.Users bll = new Maticsoft.BLL.Users();
            //DataSet dt = bll.GetList("");
            //dataGridView1.DataSource = dt.Tables[0];
        }

        public void OpenForm(Form form,bool isAdd = false)
        {
            foreach (Form item in this.MdiChildren)
            {
                if (item.GetType() == form.GetType())
                {
                    item.Activate();
                    return;
                }
            }

            if (!isAdd)
            {
                form.Show();
                form.MdiParent = this;
                form.WindowState = FormWindowState.Maximized;
            }
            else
            {
                form.ShowDialog();
            }

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            DataSet dt = bllUsers.GetList("");
            
        }

        private void 系统管理ToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void uiToolTip1_Popup(object sender, PopupEventArgs e)
        {

        }

        private void timer1_Tick(object sender, EventArgs e)
        {

        }

        private void toolStripLabel2_Click(object sender, EventArgs e)
        {
            toolStripLabel2.Text = $"系统时间：{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}";
        }

        private void toolStripLabel1_Click(object sender, EventArgs e)
        {

        }

        private void 用户列表toolStripButton1_Click(object sender, EventArgs e)
        {
            OpenForm(new UserList());
        }

        private void 用户添加toolStripButton2_Click(object sender, EventArgs e)
        {
            OpenForm(new UserAdd(), true);
        }

        private void 客户列表toolStripButton3_Click(object sender, EventArgs e)
        {
            OpenForm(new CustomerList());
        }

        private void 客户添加toolStripButton4_Click(object sender, EventArgs e)
        {
            OpenForm(new CustomerAdd(), true);
        }

        private void 产品列表toolStripButton5_Click(object sender, EventArgs e)
        {
            OpenForm(new ProductList());
        }

        private void 产品添加toolStripButton6_Click(object sender, EventArgs e)
        {
            OpenForm(new ProductAdd(), true);
        }

        private void 注销ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Restart();
        }

        private void 退出系统ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("你确定要退出系统吗？", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Application.Exit();
            }
        }

        private void 客户列表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(new CustomerList());
        }

        private void 客户添加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(new CustomerAdd(), true);
        }

        private void 用户列表ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(new UserList());
        }

        private void 用户添加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(new UserAdd(), true);
        }

        private void 产品列表ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            OpenForm(new ProductList());
        }

        private void 产品添加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenForm(new ProductAdd(), true);
        }
    }
}
